﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.Statistics.IView;
using MINERP.Statistics.Presenter;
using DevExpress.XtraEditors.Controls;

namespace MINERP.Statistics.Forms
{
    public partial class FrmWaste : Form, IWaste
    {
        public FrmWaste()
        {
            InitializeComponent();
            dateTimePickerStartTime.DateTime = DateTime.Now.Date;
            dateTimePickerEndTime.DateTime = DateTime.Now;
        }

        private static FrmWaste instance = null;
        public static FrmWaste Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmWaste();
                }
                if (instance.IsDisposed)
                {
                    instance = new FrmWaste();
                }
                return instance;
            }
        }
        PWaste _presenter;
        private void FrmWaste_Load(object sender, EventArgs e)
        {
            _presenter = new PWaste(this);
            _presenter.Init();
            this.StartTime = Convert.ToDateTime(dateTimePickerStartTime.Text);
            this.EndTime = Convert.ToDateTime(dateTimePickerEndTime.Text);


        }

        #region IWaste 成员

        //public int PrinterId
        //{
        //    get;
        //    set;
        //}

        //public int PaperTypeId
        //{
        //    get;
        //    set;
        //}

        //public int PaperFaceId
        //{
        //    get;
        //    set;
        //}
        public int OperatorId
        {
            get;
            set;
        }
        public List<string> UserNameList
        {
            get;
            set;
        }
        public DateTime StartTime
        {
            get;
            set;
        }
        public DateTime EndTime
        {
            set;
            get;
        }

        public void BingDingOperator(List<MINERP.MODEL.FoundationModel.User_Info> list)
        {
            //comboBoxOperator.DisplayMember = "UserName";
            //comboBoxOperator.ValueMember = "UserName";
            //comboBoxOperator.DataSource = list;
            //this.OperatorId = list[0].UserID;
            comboBoxOperator.Properties.DataSource = list;
            comboBoxOperator.Properties.DisplayMember = "UserName";
            comboBoxOperator.Properties.ValueMember = "UserName";
            foreach (CheckedListBoxItem item in comboBoxOperator.Properties.Items)
            {
                item.CheckState = CheckState.Checked;
            }  
            List<string> listuser = new List<string>();
            foreach (var item in list)
            {
                listuser.Add(item.UserName);
            }
            UserNameList = listuser;
           
        }

        public void BingDingPaperFace(List<MINERP.MODEL.FoundationModel.PaperFace_Info> list)
        {
            //comboBoxPaperFace.DisplayMember = "Name";
            //comboBoxPaperFace.ValueMember = "PaperFaceID";
            //comboBoxPaperFace.DataSource = list;


            //this.PaperFaceId = list[0].PaperFaceID;
        }

        public void BingdingPaperType(List<MINERP.MODEL.FoundationModel.PaperType_Info> list)
        {
            //comboBoxPaperType.DisplayMember = "Name";
            //comboBoxPaperType.ValueMember = "PaperTypeID";
            //comboBoxPaperType.DataSource = list;

            //this.PaperTypeId = list[0].PaperTypeID;
        }
        #endregion

        private void buttonOK_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            buttonOK.Enabled = false;
            try
            {

                //reportWaste.RegisterData(_presenter.GetWaste(), "Waste", FastReport.Data.BOConverterFlags.BrowsableOnly, 3);
                //reportWaste.SetParameterValue("Waste", _presenter.GetWaste());
                reportWaste.Preview = previewControl1;
                reportWaste.Load(Application.StartupPath + "\\Waste.frx");
                reportWaste.RegisterData(_presenter.GetWaste());
                previewControl1.Refresh();
                previewControl1.Show();
                reportWaste.Show();
                //previewControl1.da
                //reportWaste.Show();
            }
            finally
            {
                buttonOK.Enabled = true;
                this.Cursor = Cursors.Default;
            }
        }

        private void dateTimePickerStartTime_ValueChanged(object sender, EventArgs e)
        {
            this.StartTime = Convert.ToDateTime(dateTimePickerStartTime.Text);
        }

        private void dateTimePickerEndTime_ValueChanged(object sender, EventArgs e)
        {
            this.EndTime = Convert.ToDateTime(dateTimePickerEndTime.Text);
        }

        private void comboBoxOperator_Properties_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
        {
            //if (comboBoxOperator.SelectedIndex == 0)
            //{
            //    this.OperatorId = 0;
            //}
            //else
            //{
            //    UserName = comboBoxOperator.SelectedValue.ToString();
            //}
            List<string> temList = new List<string>();
            foreach (CheckedListBoxItem item in comboBoxOperator.Properties.Items)
            {

                if(item.CheckState == CheckState.Checked)
                {
                    temList.Add(item.Value.ToString());
                }

            }
            UserNameList = temList;
        }








    }
}
